package com.seeyon.apps.kk.manager.restImpl;

import java.util.Map;

import org.apache.commons.collections.MapUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.seeyon.apps.kk.manager.BaseManager;
import com.seeyon.apps.kk.manager.FreemarkFlowManager;
import com.seeyon.kk.utils.ValueUtils;

/**
 * 档案资料流程自动发起实现类
 * 
 * @author seeyon
 *
 */
public class DocumentHandoutImpl extends BaseManager {

	private static final Log log = LogFactory.getLog(DocumentHandoutImpl.class);

	private FreemarkFlowManager freemarkFlowManager;

	public FreemarkFlowManager getFreemarkFlowManager() {
		return freemarkFlowManager;
	}

	public void setFreemarkFlowManager(FreemarkFlowManager freemarkFlowManager) {
		this.freemarkFlowManager = freemarkFlowManager;
	}

	/**
	 * 自动发起档案资料利用审批表流程
	 * 
	 * @param params
	 *            参数参照 addCreateXML.ftl
	 */
	@SuppressWarnings("finally")
	public long autoDocumentFlow(Map<String, Object> params) {
		long sendCollaboration = -1L;
		try {
			String xmlData = this.freemarkFlowManager
					.fltTemplateIntoString("datasync/archives/addCreateXML.ftl", params);
			sendCollaboration = this.freemarkFlowManager.sendCollaboration(MapUtils.getString(params, "loginName"),
					ValueUtils.getConfig().getString("shkk.docTemplateCode"), null, xmlData, null, "0", null);
			log.info("=================shkk========自动发起数字档案流程=========:" + sendCollaboration);
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			log.info("=================shkk=========自动发起数字档案流程错误=========" + e.getMessage() + "《" + params + "》");
		} finally {
			return sendCollaboration;
		}
	}
}
